home *** CD-ROM | disk | FTP | other *** search
- '┌─────────────────────────────────────────────────────────────────────┐
- '└── beginning of crossbas.bas ────────────────────────────────────────┘
- '┌─────────────────────────────────────────────────────────────────────┐
- '│ CrossBas.bas │
- '│ │
- '│ This program will scan a Power-BASIC source file and create a cross-│
- '│ reference table of variable names and labels. To do this we must │
- '│ first read in all words in the file. We can skip all text to the │
- '│ right of "REM" or "'" remark identifiers. After words are read in, │
- '│ we must compare them with PBASIC reserved words and metastatements. │
- '│ Finally, we alphabetize the remaining words and print them out, one │
- '│ word to a line, followed by the line number(s) where these words │
- '│ were found. The list will bs sorted without regard to case. │
- '│ │
- '│ Command Line Switches: │
- '│ /BW Set screen colors to Black & White │
- '│ /U Print all cross-reference variables in upper-case. │
- '│ /P Print page headers and footers. │
- '│ /S Print cross-reference list to the screen as well as to file. │
- '│ /L:n Left margin n spaces. │
- '│ /W:n Word array dimension over-ride. │
- '│ │
- '│ │
- '│ Modification History: │
- '│ │
- '│ Uploaded CrossBas version 1.00P to Compuserve PCVENB, Spectra │
- '│ forum. Converted for Power-BASIC. 12/ 1/90 │
- '│ │
- '│ Added /bw switch to allow black and white screen color override. │
- '│ Also, added color to default screen. 12/ 1/90 │
- '│ │
- '│ Uploaded CrossBas version 1.00 to CompuServe BPROGA forum, LIB 9. │
- '│ (Originally written for and in Turbo-BASIC.) │
- '│ │
- '│ KEYWORDS: CROSS-REFERENCE, TABLE, LIST, NON-RESERVED WORDS │
- '│ │
- '│ Description: CrossBas will read in a Turbo-BASIC source file and │
- '│ create an alphabetized cross-reference listing of non- │
- '│ reserved words, i.e., variable, sub-program, function and │
- '│ label names, along with the physical line number(s) where they │
- '│ appear. The list is printed to file. Handy for cleaning │
- '│ up unused variable names, labels, etc. 11/13/89 │
- '│ │
- '│ You are free to use this program as you wish. If you find any │
- '│ problems with if, please let me know about it. If you have any │
- '│ suggestions as to how to improve is, also, I'd appreciate your │
- '│ help. │
- '│ │
- '│ │
- '│ Lester L. Noll CompuServe id: 72250,2551 │
- '│ copyright (c) 11/13/89, 1990 │
- '│ │
- '└─────────────────────────────────────────────────────────────────────┘
- Title$ ="CrossBas.bas"
- Ver$ ="1.00P"
- Copyright$ ="Copyright (c) 11/13/90, Lester L. Noll"
- CisId$ ="72250,2551"
-
- '┌── main program ─────────────────────────────────────────────────────┐
- Main:
-
- GOSUB Initialize 'Initialize screen, integers.
- GOSUB InitScreen 'Put up init screen.
- GOSUB ReadCmdLine 'Read the DOS command line.
- GOSUB OpenFiles 'Open source files and check name
- ' validity.
- GOSUB CalcFileNames 'Parse filename from full path.
- GOSUB ReadDefaults 'Read defaults from default file.
- ' GOSUB CheckStringSpace 'Check there is enough string space
- ' for infile words.
- '(Took this out for PBASIC version)
- GOSUB CalcWordArraySize 'Calc word array dimension.
- GOSUB PrintScreenTop 'Print top of screen report.
- GOSUB ReadAndParseData 'Read source file lines and parse
- ' them into words.
- GOSUB PrintScreen1 'Print read and parse report.
- GOSUB Compare 'Compare source words with Power-
- ' BASIC reserved words.
- GOSUB PrintScreen2 'Print compare report.
- GOSUB SortWords 'Sort non-reserved words.
- GOSUB PrintScreen3 'Print sort report.
- GOSUB PrintList 'Print sorted words to file.
- GOSUB PrintReportBtm 'Print summary report to file.
- GOSUB PrintScreen4 'Print print-list report.
- CLOSE
- DELAY 1
- CALL FlushKeyBuf
- END
-
- '└─────────────────────────────────────────────────────────────────────┘
-
- '─── initialize ────────────────────────────────────────────────────────
- Initialize:
-
- $DYNAMIC 'All arrays default to dynamic. They
- ' can be erased after you're finished
- ' using them.
- SCREEN 0,1: WIDTH 80: CLS 'Color board, 80 columns.
- CLOSE 'Close all open files.
- DEFINT A-Z 'Default all numbers to integer.
- FG =14 'Foreground color.
- BG =1 'Background color.
- KEY OFF 'Turn BASIC soft keys off.
- DIM SaveRow(10), SaveCol(10) 'Screen location arrays.
- ON ERROR GOTO MemoryError 'Memory and other error trap.
- RETURN
-
- '─── print init screen ─────────────────────────────────────────────────
- InitScreen:
-
- COLOR FG,BG
- LOCATE 10,18
- PRINT "Initializing CrossBas. Please wait ";
- COLOR FG+16,BG 'Blink screen.
- PRINT "..."
- COLOR FG,BG
- RETURN
-
- '─── include files ─────────────────────────────────────────────────────
- $INCLUDE "crossbas.inc" 'CrossBas subprograms file.
-
- '─── read command line ─────────────────────────────────────────────────
- ReadCmdLine: 'Read the DOS command line and use variables found
- ' there as the input PBASIC source file, the output
- ' cross-reference table file, and the '/u,' '/s,'
- ' '/l:n,' '/w:n,' and '/p' switches. The first
- ' variable that doesn't start with one of the switch
- ' strings is assumed to be the source. If a second
- ' such string is found, it is assumed to be the output
- ' file. If no output file is found, the input filename
- ' appended with '.cb' becomes the output filename.
- ' Other than input/output filename sequence, other
- ' parameters can be entered in any order.
-
- ON ERROR GOTO MemoryError 'Memory and other errors trap.
- PageFlag =0 'Print page breaks and headers (1).
- ScreenFlag =0 'Print list to screen also (1).
- UcaseFlag =0 'Print list in upper-case (1).
- LMarginMax =8 'Max left margin value.
- WordDimFlag =0 'Word array dimension over-ride flag.
- WordArrayDim =0 'Word array dimension over-ride.
- InFile$ ="" 'Input (source) file name and path.
- OutFile$ ="" 'Output file name and path.
-
- CALL DimCmdLine(DimCmd) 'Get number of parameters on cmd line.
- DIM Parameter$(1:DimCmd) 'Max number of cmd line parameters.
- CALL ParseCmdLine(Parameter$()) 'Get command line parameters.
-
- FOR I = 1 TO DimCmd
- SELECT CASE LEFT$(UCASE$(Parameter$(I)),2)'Check the left two
- ' characters of the DOS command
- ' line parameter.
- CASE "/B" : FG=7: BG=0 'Black & White over-ride
- COLOR FG,BG
- CASE "/P" : PageFlag =-1 'Is it the page flag? (Print
- ' a page header to the output
- ' file.)
- CASE "/S" : ScreenFlag =-1 'Is it the screen flag? (Print
- ' the output file to the screen.)
- CASE "/U" : UcaseFlag =-1 'Is it the upper case flag?
- ' (Print variable names in upper
- ' case to output file.)
- CASE "/L" : GOTO ReadCmdLine.2 'Set the left margin.
- CASE "/W" : GOTO ReadCmdLine.3 'Set word array dim.
- CASE ELSE : GOTO ReadCmdLine.1 'File name.
- END SELECT
- GOTO ReadCmdLine.9
-
- ReadCmdLine.1: 'Calculate InFile$ and
- ' OutFile$ names.
- IF InFile$ ="" THEN 'If no input file specified
- InFile$ =Parameter$(I) ' this is it.
- ELSEIF OutFile$ ="" THEN 'If no output file specified
- OutFile$ =Parameter$(I) ' this is it.
- END IF
- GOTO ReadCmdLine.9
-
- ReadCmdLine.2: 'Calculate left margin value.
- LMargin =INSTR(Parameter$(I),":") 'If colon not found then left
- IF LMargin >0 THEN ' margin switch is invalid.
- Temp$ =MID$(Parameter$(I),LMargin+1)
- IF VAL(Temp$) >0 THEN LMargin =VAL(Temp$) 'If left margin value is a
- IF LMargin >LMarginMax THEN LMargin =LMarginMax ' valid number use it.
- END IF
- GOTO ReadCmdLine.9
-
- ReadCmdLine.3: 'Calculate word array dim value.
- WordArrayDim =INSTR(Parameter$(I),":") 'If colon not found then word
- IF WordArrayDim >0 THEN ' array dim switch is invalid.
- Temp$ =MID$(Parameter$(I),WordArrayDim+1)
- IF VAL(Temp$) >0 THEN WordArrayDim =VAL(Temp$) 'If word array size
- ELSE ' is a value then keep it,
- WordArrayDim =0 ' otherwise dump it.
- END IF
- WordDimFlag =-1 'Word array dim over-ride flag,
- ' whether 0 or not.
-
- ReadCmdLine.9:
- NEXT I 'Next command line parameter.
-
- IF InFile$ ="" THEN NoFileSpec 'If no input file specified,
- ' print message and quit.
- IF OutFile$ ="" THEN 'If no output file specified ..
- IF INSTR(InFile$,".") =0 THEN 'If input filename has no ex-
- OutFile$ =InFile$ +".cb" ' tension then use it with '.cb'
- ' appended as output filename.
- ELSE
- OutFile$ =LEFT$(InFile$,INSTR(InFile$,".")-1) +".cb" ''If input file-
- ' name has an extension, use
- ' left part of filename appended
- ' with '.cb' as output filename.
- END IF
- END IF
- ERASE Parameter$ 'Deallocate space for command
- ' line parameter array.
- RETURN
-
- '─── open files ────────────────────────────────────────────────────────
- OpenFiles:
-
- ON ERROR GOTO InFileError 'Trap infile errors.
- OPEN InFile$ FOR INPUT AS #1 'Open input source file.
- InFileSize! =LOF(1) 'Infile size.
-
- ON ERROR GOTO OutFileError 'Trap outfile errors.
- OPEN OutFile$ FOR OUTPUT AS #2 'Make sure this filename will be
- ' valid for when we need it.
- ON ERROR GOTO MemoryError 'Memory and other error trap.
- CLOSE #2 'We don't need this now.
- RETURN
-
- '─── calculate file names and paths ────────────────────────────────────
- CalcFileNames: 'Separate the file names from the
- ' complete file paths for use in
- CALL CalcName(InFile$,InFileName$) ' reports.
- CALL CalcName(OutFile$,OutFileName$)
- RETURN
-
- '─── read in defaults from default file ────────────────────────────────
- ReadDefaults: 'Read default file values.
-
- DefFile$ ="crossbas.def"
- ON ERROR GOTO NulError 'If file not found, then ignore the
- OPEN DefFile$ FOR INPUT AS #11 ' error and create a default file.
- ON ERROR GOTO MemoryError 'Memory and other error trap.
-
- IF ErrorFlag THEN
- ErrorFlag =0 'Reset error flag.
- AvgWordLen =5 'Average bytes per non-comment words.
- PackingFactor! =.7 'Percent of file that is non-comment.
- OPEN DefFile$ FOR OUTPUT AS #11
- WRITE #11,AvgWordLen,PackingFactor!
- PRINT #11,STRING$(72,"-")
- PRINT #11,"This is the CrossBas default file. Do not make any ";_
- "format changes to"
- PRINT #11,"the first line of this file!
- PRINT #11,
- PRINT #11,"The first field is the average bytes per word you ";_
- "expect to find in"
- PRINT #11,"your source file. We are concerned with non-comment ";_
- "words only."
- PRINT #11,TAB(66);"[def: 5]"
- PRINT #11,
- PRINT #11,"The second field is the packing factor, the ratio of ";_
- "non-comment words"
- PRINT #11,"to source file length. This is expressed as a real ";_
- "number less then 1."
- PRINT #11,TAB(66);"[def: .7]"
- ELSE
- INPUT #11,AvgWordLen,PackingFactor!
- END IF
- CLOSE #11 'Close the defaults file.
- RETURN
-
-
- '─── check string space vs. effective infile size ──────────────────────
- CheckStringSpace: 'Check there is enough string space for the infile
- ' words.
- '(Took this out for PBASIC version.)
-
- IF InFileSize! *PackingFactor! >FRE(S$) THEN 'If the effective infile size
- ' is bigger than the free
- ' string space area then
- CLS ' quit.
- CLOSE
- PRINT "The calculated effective size of source file, ";
- PRINT UCASE$(InFileName$); ", is ";
- PRINT USING "######,"; InFileSize! *PackingFactor!;
- PRINT " bytes, "
- PRINT "but only ";
- PRINT USING "######,"; FRE(S$);
- PRINT " bytes of string space are available."
- PRINT "Your current default packing factor is ";
- PRINT USING ".##"; PackingFactor!;
- PRINT " (";
- PRINT USING "###.##"; PackingFactor! *100;
- PRINT " %)"
- PRINT
- PRINT "You have two options:"
- PRINT "1. If you think the packing factor may be too large, ";
- PRINT "try changing it in the";
- PRINT " defaults file, CROSSBAS.DEF."
- PRINT "2. Try breaking the file up into one main file and one or ";
- PRINT "more include files."
- DELAY 1
- CALL FlushKeyBuf
- END
- END IF
- RETURN
-
- '─── calculate word array size ─────────────────────────────────────────
- CalcWordArraySize: 'Calculate the approximate
- ' number of non-reserved words
- ' in the source file.
-
- IF NOT WordDimFlag THEN 'If no '/w:n' command line over-
- ' ride value, then calculate one.
- WordArraySize =FIX(InFileSize! *PackingFactor! /AvgWordLen)
- 'Divide file size by avg
- ELSE ' word length.
- WordArraySize =WordArrayDim 'Otherwise use over-ride value.
- END IF
- RETURN
-
- '─── read in source file lines ─────────────────────────────────────────
- ReadAndParseData: 'Read in source file lines. Parse out
- ' words and save them.
-
- ON ERROR GOTO MemoryError 'Memory and other error trap.
- ArrayBytes& =0 'Bytes in string space. At present,
- ' this is used only to calculate
- ' the file packing factor. The packing
- ' factor is the percent of comment to
- ' non-comment words found in a file.
- DIM Word$(1:WordArraySize) 'Word array.
- DIM LineNo(1:WordArraySize) 'Line number array.
- Wp =0 'Word number.
- L =0 'Initial input file value.
- SP$ =TIME$ 'Compare start time.
- GOSUB InitStatusBarP 'Initialize status bar.
- DO UNTIL EOF(1) 'Repeat until end of input file
- ' encountered.
- INCR L 'Increment line number.
- LINE INPUT #1,TextLine$ 'Read a source file line.
- GOSUB ParseTextLine 'Parse the source file line.
- IF FRE(S$) <300 THEN ERROR 14: GOTO MemoryError 'Anticipate string
- ' space error.
- GOSUB UpdateStatusBarP 'Update screen status line.
- LOOP 'Do again.
- EP$ =TIME$ 'Parse end time.
- CLOSE #1 'Close input files.
- LMax =L 'Total lines in source file.
- WpMax =Wp 'Total non-reserved words.
- RETURN
-
-
- '─── parse text line ───────────────────────────────────────────────────
- ParseTextLine:
-
- DelimitFlag =-1 'Last char was a delimiter.
- QuoteFlag =0 'Inside a text literal--ignore.
- NumberFlag =0 'Inside a number--ignore.
- Temp$ ="" 'Max chars in source file line.
- CMax =LEN(TextLine$)
-
- FOR C =1 TO CMax
- Char$=MID$(TextLine$,C,1) 'Read one char at a time.
- SELECT CASE Char$
- CASE "'" : GOTO ParseTextLine.5 'Remark char.
- CASE " " : GOTO ParseTextLine.1 'Delimiter.
- CASE "" : GOTO ParseTextLine.1 'Delimiter.
- CASE "=" : GOTO ParseTextLine.1 'Delimiter.
- CASE ">" : GOTO ParseTextLine.1 'Delimiter.
- CASE "<" : GOTO ParseTextLine.1 'Delimiter.
- CASE "*" : GOTO ParseTextLine.1 'Delimiter.
- CASE "/" : GOTO ParseTextLine.1 'Delimiter.
- CASE "-" : GOTO ParseTextLine.1 'Delimiter.
- CASE "+" : GOTO ParseTextLine.1 'Delimiter.
- CASE "\" : GOTO ParseTextLine.1 'Delimiter.
- CASE "_" : GOTO ParseTextLine.1 'Delimiter.
- CASE "," : GOTO ParseTextLine.1 'Delimiter.
- CASE ";" : GOTO ParseTextLine.1 'Delimiter.
- CASE ":" : GOTO ParseTextLine.1 'Delimiter.
- CASE "#" : GOTO ParseTextLine.6 '<#>
- CASE "." : GOTO ParseTextLine.7 '<.>
- CASE "(" : GOTO ParseTextLine.1 'Delimiter.
- CASE ")" : GOTO ParseTextLine.1 'Delimiter.
- CASE CHR$(9) : GOTO ParseTextLine.1 '<TAB>
- CASE CHR$(13) : GOTO ParseTextLine.1 '<CR>
- CASE "0" TO "9" : GOTO ParseTextLine.3 'Number.
- CASE CHR$(34) : GOTO ParseTextLine.2 'Quote mark.
- CASE ELSE : GOTO ParseTextLine.4 'Normal text.
- END SELECT
-
-
- ParseTextLine.1: 'Delimiter found.
- IF QuoteFlag THEN ParseTextLine.8 'If within a quote,
- ' dump char and get next.
-
- IF DelimitFlag THEN ParseTextLine.8 'If last char was delimiter,
- ' just dump this one and get
- ' next char.
-
- IF NumberFlag THEN 'If last char was number reset
- NumberFlag =0 ' number flag,
- DelimitFlag =-1 ' reset delimit flag,
- GOTO ParseTextLine.8 ' and get next char.
- END IF
-
- DelimitFlag =-1 'Set delimit flag.
- IF UCASE$(Temp$) ="DATA" THEN ParseTextLine.9 'If the word is DATA or REM,
- IF UCASE$(Temp$) ="REM" THEN ParseTextLine.9 ' ignore rest of line and
- ' get next.
- IF NOT Temp$ ="" THEN
- INCR Wp
- Word$(Wp) =Temp$ 'Save word and line num in
- LineNo(Wp) =L ' word array and get ready for
- ArrayBytes& =ArrayBytes& +LEN(Word$(Wp)) ' next word.
- Temp$ =""
- IF Char$ ="(" THEN Word$(Wp) =Word$(Wp) +"()" 'If it is function, proc-
- IF Char$ ="[" THEN Word$(Wp) =Word$(Wp) +"[]" ' edure or statement that
- END IF ' passes variables,
- ' append the brackets.
- IF Char$ ="'" THEN ParseTextLine.9
- GOTO ParseTextLine.8
-
- ParseTextLine.2: 'Quote mark found.
- IF QuoteFlag THEN 'If within a quote string,
- QuoteFlag =0 ' reset quote flag, dump char
- GOTO ParseTextLine.8 ' and get next character.
- ELSE
- QuoteFlag =-1 'If quote string just starting,
- GOTO ParseTextLine.8 ' set quote flag.
- END IF
-
-
- ParseTextLine.3: 'Number character.
- IF QuoteFlag THEN GOTO ParseTextLine.8 'If within a quote,
- ' dump char and get next.
- IF NumberFlag THEN GOTO ParseTextLine.8
- IF NOT DelimitFlag THEN GOTO ParseTextLine.4 'If number is within
- ' or at end of a variable
- ' name it is a normal char.
- NumberFlag =-1 'Set number flag.
- DelimitFlag =0
- GOTO ParseTextLine.8 'Otherwise it is an immediate
- ' number and ignored.
-
-
- ParseTextLine.4: 'Normal character.
- IF QuoteFlag THEN ParseTextLine.8 'If within a quote.
-
- DelimitFlag =0 'Reset delimiter flag.
- NumberFlag =0 'Reset number flag.
-
- Temp$ =Temp$ +Char$ 'Build the next word.
- GOTO ParseTextLine.8
-
- ParseTextLine.5: 'Remark char encountered.
- IF NOT QuoteFlag THEN 'IF not inside quote string,
- GOTO ParseTextLine.9 ' disregard rest of line
- ELSE ' and get next line.
- GOTO ParseTextLine.8 'Else get next char.
- END IF
-
- ParseTextLine.6: '# char.
- IF DelimitFlag THEN ParseTextLine.8 'Dump char and get next.
- GOTO ParseTextLine.4 'If occurs in middle or end of
- ' word, keep it.
-
- ParseTextLine.7: '. char.
- IF NumberFlag THEN ParseTextLine.8 'Dump char and get next.
- IF DelimitFlag THEN 'If char occurs at start of
- NumberFlag =-1 ' word, assume it is a
- DelimitFlag =0 ' number.
- GOTO ParseTextLine.8
- END IF
- GOTO ParseTextLine.4 'If not a part of a number,
- ' treat it as a normal char.
-
- ParseTextLine.8: 'Get next character.
- NEXT C
-
- ParseTextLine.9:
- IF NOT Temp$ ="" THEN
- INCR Wp
- Word$(Wp) =Temp$
- LineNo(Wp) =L
- ArrayBytes& =ArrayBytes& +LEN(Word$(Wp))
- Temp$ =""
- IF Char$ ="(" THEN Word$(Wp) =Word$(Wp) +"()" 'If it is an array or
- IF Char$ ="[" THEN Word$(Wp) =Word$(Wp) +"[]" ' function or procedure
- END IF ' that passes variables,
- RETURN ' append the brackets.
-
- '─── compare with reserved words ───────────────────────────────────────
- Compare: 'Compare each source file word with all Power-BASIC reserved
- ' words that start with the same first letter as the word.
-
- ON ERROR GOTO MemoryError 'Memory and other error trap.
- DIM PBWord$(1:36) 'Power-BASIC reserved words.
- Wc =0 'Compare word index.
- SC$ =TIME$ 'Compare start time.
- GOSUB InitStatusBarC 'Set up status bar or compare.
-
- FOR Wp = 1 TO WpMax
- SELECT CASE LEFT$(UCASE$(Word$(Wp)),1) 'Power-BASIC words starting
- CASE "A" : RESTORE DataA ' with ...
- CASE "B" : RESTORE DataB
- CASE "C" : RESTORE DataC
- CASE "D" : RESTORE DataD
- CASE "E" : RESTORE DataE
- CASE "F" : RESTORE DataF
- CASE "G" : RESTORE DataG
- CASE "H" : RESTORE DataH
- CASE "I" : RESTORE DataI
- CASE "J" : RESTORE DataJ
- CASE "K" : RESTORE DataK
- CASE "L" : RESTORE DataL
- CASE "M" : RESTORE DataM
- CASE "N" : RESTORE DataN
- CASE "O" : RESTORE DataO
- CASE "P" : RESTORE DataP
- CASE "Q" : RESTORE DataQ
- CASE "R" : RESTORE DataR
- CASE "S" : RESTORE DataS
- CASE "T" : RESTORE DataT
- CASE "U" : RESTORE DataU
- CASE "V" : RESTORE DataV
- CASE "W" : RESTORE DataW
- CASE "X" : RESTORE DataX
- CASE "Y" : RESTORE DataY
- CASE "Z" : RESTORE DataZ
- CASE "$" : RESTORE DataDs 'Dollar sign (metastatements).
- CASE ELSE : GOTO Compare.1 'Else save it.
- END SELECT
-
- FOR I =1 TO 30 'Blank out array.
- PBWord$(I) =""
- NEXT I
-
- I =0 'Blank out the T-B word array.
- DO
- INCR I
- READ PBWord$(I)
- LOOP UNTIL PBWord$(I) ="0"
-
- FOR J =1 TO I -1 'Read Power-BASIC words for
- IF UCASE$(Word$(Wp)) =PBWord$(J) GOTO Compare.2 ' comparisons.
- NEXT J
-
- Compare.1:
- INCR Wc 'Increment the compare word
- GOSUB UpdateStatusBarC ' index, update the status bar
- Word$(Wc) =Word$(Wp) ' and save word and line no.
- LineNo(Wc) =LineNo(Wp) ' to word array.
-
- Compare.2:
- NEXT Wp
-
- EC$ =TIME$ 'Compare end time.
- WcMax =Wc 'Non-Power-BASIC reserved words.
- FOR I =Wc +1 TO Wp 'Blank out extra word array
- Word$(I) ="" ' elements.
- LineNo(I) =0
- NEXT I
- ERASE PBWord$ 'Collapse T-B word array--no
- ' longer needed.
- RETURN
-
- '─── sort the non-PBASIC words ─────────────────────────────────────────
- SortWords: 'Bubble sort the non-Power-BASIC words into alpah-
- ' betical order. Added SortFlag to make it a
- ' modified bubble sort. If we make a J pass without
- ' making any swaps it means we no more passes are
- ' necessary. So it cuts the sort short after the
- ' file is in order, even though we haven't gone
- ' through all the passes. I CrossBas'd a 56k file
- ' with and without the extra sort flag setting and
- ' checking. The file contained "DEFINT A - Z" at
- ' the beginning, so it had to sort the whole file--
- ' no short cuts. Without sort flag checking the sort
- ' took 43:11. With the sort flag checking the sort
- ' took 43:29, only 18 seconds or .7% longer. There-
- ' fore, for a negligible time increase, worst-case,
- ' we can gain a great deal in cases where the file
- ' may be in a bit of order.
- SS$ =TIME$ 'Sort start time.
- GOSUB InitStatusBarS 'Set up status bar for sort.
- Ws =WcMax 'Sort index.
- FOR J =Ws TO 1 STEP -1
- FOR I =1 TO J -1
- IF UCASE$(Word$(I)) > UCASE$(Word$(I+1)) THEN 'Compare this word
- ' and the next.
- SWAP Word$(I), Word$(I+1) 'If next is lower, swap the
- SWAP LineNo(I), LineNo(I+1) ' word and its line number.
- SortFlag =-1
- END IF
- NEXT I 'Check next two words.
- GOSUB UpdateStatusBarS 'Update status bar.
- IF NOT SortFlag THEN 'If no sort on last pass,
- J =1 ' then sorting is finished.
- GOSUB UpdateStatusBarS
- END IF
- SortFlag =0 'Reset sort flag.
- NEXT J 'Make next pass.
-
- ES$ =TIME$ 'Sort end time.
- RETURN
-
- '─── print the list ────────────────────────────────────────────────────
- PrintList: 'Print the sorted list to file. If a word exists more
- ' than once, print it only once. Print word in left
- ' column. Print line numbers on the row after the
- ' word, at 6 column intervals. Extend line numbers
- ' onto the next line(s) if necessary.
-
- Page1Flag =0 'Flag for printing infor-
- ' mation at top of file.
- I =0 'Word index.
- SL =0 'Screen line number.
- PL =0 'Page line number.
- Page =1 'File page number.
- LowestL =1 'If more than one line number
- ' per word.
- Wu =0 'Unique words.
- GOSUB CalcPHeader 'Page header, if page flag.
- IF UcaseFlag THEN GOSUB SetUcase 'Convert to ucase if ucase flag.
- OPEN OutFile$ FOR OUTPUT AS #2 'Open cross-ref list file.
- SF$ =TIME$ 'Print to file start time.
- IF LMargin >0 THEN PRINT #2,CHR$(27);"l";CHR$(LMargin); 'Set left margin.
- GOSUB PrintPHeader 'Print page header, if page flag.
- GOSUB InitStatusBarF 'Set up status bar for file print.
- DO
- INCR I 'Increment word index.
- IF UcaseFlag THEN GOSUB SetUcase 'Convert to ucase if ucase flag.
- IF NOT Word$(I) =Word$(I+1) THEN 'If next word different than
- INCR PL ' this word...
- INCR SL 'Increment page and screen lines.
- GOSUB CalcInitTab 'Calc file tab values.
- PRINT #2,Word$(I); 'Print the word to file...
- IF ScreenFlag THEN PRINT Word$(I); 'If screen flag, print to screen.
- FOR J =LowestL TO I
- TabPos =TabPos +6
- IF TabPos >67 THEN 'If past right margin start
- PRINT #2, ' new line.
- IF ScreenFlag THEN PRINT
- GOSUB PageBreakCk 'Check for page break.
- GOSUB ScreenBreakCk 'Check for screen break.
- GOSUB CalcInitTab
- TabPos =TabPos +6
- INCR PL 'Increment page and screen
- INCR SL ' line numbers.
- END IF
- PRINT #2,TAB(TabPos); 'Print line numbers after
- PRINT #2,LineNo(J); ' word.
- IF ScreenFlag THEN 'If screen flag, print
- PRINT TAB(TabPos); ' to screen.
- PRINT LineNo(J);
- END IF
- NEXT J 'Print next line number.
- PRINT #2,
- IF ScreenFlag THEN PRINT
- LowestL =I +1
- GOSUB PageBreakCk 'Check for page break.
- GOSUB ScreenBreakCk 'Check for screen break.
- INCR Wu 'Increment unique word index.
- GOSUB UpdateStatusBarF 'Update status bar.
- END IF
- LOOP UNTIL I =WcMax 'Print next word.
- EF$ =TIME$ 'Print to file end time.
-
- RETURN
-
- '─── print list routines ───────────────────────────────────────────────
- SetUcase: 'Convert word to upper-case if upper case flag is set.
-
- Word$(I+1) =UCASE$(Word$(I+1))
- RETURN
-
- '─── check for page break ──────────────────────────────────────────────
- PageBreakCk: 'Count page lines. If less then 64, print next line.
- ' If 64 lines, print footer, increment page number,
- ' print page footer. If page flag is reset, footers
- ' and headers are ignored. If we page break with more
- ' line numbers to print yet, reprint the word followed
- ' by "(cont'd)"
-
- IF NOT PageFlag THEN RETURN 'If page flag is reset, skip pagebreak.
- IF PL <64 THEN RETURN 'If page number less then 64 print next line.
- GOSUB PrintPFooter 'Print page footer.
- INCR Page 'Increment page number.
- GOSUB PrintPHeader 'Print page header.
- IF (LowestL <I) AND (J <>I) THEN 'If more line numbers to print for word
- Word$(I) =Word$(I) +"(cont'd)" ' on next page, reprint word.
- GOSUB CalcInitTab
- PRINT #2,Word$(I);
- END IF
- RETURN
-
- '─── check for screen break ────────────────────────────────────────────
- ScreenBreakCk: 'Count screen lines. If less then 22, print next line.
- ' If 22 lines, stop screen scroll and wait for keypress.
-
- IF NOT ScreenFlag THEN RETURN 'If screen flag is reset, this
- ' isn't necessary.
- IF (SL <22) AND (I <>WcMax) THEN RETURN 'If screen line number is 22
- PRINT TAB(20);"... press Q to Quit screen list, or any key to continue";
- CALL FlushKeyBuf ' stop scroll and wait for
-
- WHILE NOT INSTAT: WEND 'Wait for key press
- LOCATE ,1
- PRINT SPACE$(79);
- LOCATE ,1
- InK$ =INKEY$
- SELECT CASE UCASE$(InK$) 'Quit screen list by pressing Q
- CASE "Q" : ScreenFlag =0 ' or <ESC>. Any other key
- CASE CHR$(27) : ScreenFlag =0 ' continues screen list.
- END SELECT
- CALL FlushKeyBuf 'Flush the key buffer.
- SL =0 'Reset screen line number.
- RETURN
-
- '─── calculate initial tab space ───────────────────────────────────────
- CalcInitTab: 'Calculate the output file tab position for line
- ' numbers.
-
- TabPos =18
- WHILE LEN(Word$(I)) >=(TabPos +6) 'Set tab position to first
- TabPos =TabPos +6 ' increment of 6 longer then
- WEND ' the length of the word.
- RETURN
-
- '─── calculate page header string ──────────────────────────────────────
- CalcPHeader: 'Calc the page header string, consisting of today's
- ' date, the source file name and the page number.
-
- PHeaderA$ =DATE$ +fnCenterJust$("CrossBas: " +UCASE$(InFileName$),51) +_
- " Page "
- PHeaderB$ ="ver. "+Ver$+" "+fnCenterJust$(_
- "CrossBas, a Source File Cross-Referencer for Power-BASIC",56)
- RETURN
-
- '─── print page header ────────────────────────────────────────────────
- PrintPHeader: 'Print output file headers and footers, if page flag
- ' is set.
-
- IF PageFlag THEN 'If page flag is set
- PRINT #2, ' print blank rows.
- PRINT #2,
- PL =3 'Initial page line value.
- GOSUB PrintPHeader1 'Print the upper header.
- IF NOT Page1Flag THEN GOSUB PrintPTop 'If this is page 1 print
- ' a top of report header.
- IF I <WcMax THEN GOSUB PrintPHeader2 'IF this is not the last page
- ' summary report page, print
- ELSE ' the lower header.
- PRINT #2,
- PL =2 'Initial page line value.
- IF NOT Page1Flag THEN GOSUB PrintPTop 'If page flag is reset, then
- ' if this is page 1, print a
- ' top of report header.
- END IF
- RETURN
-
- '─── print top of page ─────────────────────────────────────────────────
- PrintPTop: 'Print this at the top of the cross-ref list, whether
- ' the page flag is set or not.
- IF NOT PageFlag THEN
- PRINT #2,DATE$;fnCenterJust$("CrossBas Cross-Reference List",52);" ";_
- TIME$
- INCR PL
- END IF
- PRINT #2,fnCenterJust$("Source: "+UCASE$(InFileName$) +" "+_
- "List: "+UCASE$(OutFileName$),72)
- PRINT #2,
- INCR PL,2
- Page1Flag =-1
- RETURN
-
- '─── print page header 1 ───────────────────────────────────────────────
- PrintPHeader1: 'Print the upper page header.
- PRINT #2, PHeaderA$;
- PRINT #2, USING "###";Page
- PRINT #2, PHeaderB$
- INCR PL,4
- RETURN
-
- '─── print page header 2 ───────────────────────────────────────────────
- PrintPHeader2: 'Print the lower page header.
- PRINT #2,"Variable/Label/Proc";TAB(25);"Physical Line Number"
- INCR PL
- RETURN
-
- '─── print page footer ─────────────────────────────────────────────────
- PrintPFooter: 'Print the page footer blank lines.
- IF PageFlag THEN
- PRINT #2,CHR$(12); 'Form feed character.
- END IF
- RETURN
-
- '─── print bottom of report statistics ─────────────────────────────────
- PrintReportBtm: 'Print the summary report at the bottom of the output
- ' file, whether page flag is set or not.
-
- PRINT #2,CHR$(12); 'Pagebreak.
- INCR Page
- GOSUB PrintPHeader 'Print a page header.
- IF NOT PageFlag THEN
- PRINT #2,
- PRINT #2,DATE$;fnCenterJust$(TOSTitle$,52);" ";TIME$
- END IF
- PRINT #2,fnCenterJust$("-+-+-+- Summary Report -+-+-+-",72)
- PRINT #2,
- PRINT #2,"Options: Upper-case: ";
- IF UcaseFlag THEN PRINT #2,"Yes"; ELSE PRINT #2,"No";
- PRINT #2,TAB(30);"Screen: ";
- IF ScreenFlag THEN PRINT #2,"Yes"; ELSE PRINT #2,"No";
- PRINT #2,TAB(49);"Paginate: ";
- IF PageFlag THEN PRINT #2,"Yes" ELSE PRINT #2,"No"
- PRINT #2," Left Margin:";STR$(LMargin);
- PRINT #2,TAB(30);"ArrayDim:";
- IF WordDimFlag THEN
- PRINT #2,STR$(WordArrayDim) 'Print over-ride value.
- ELSE
- PRINT #2," No o/r" 'No over-ride (/w:n).
- END IF
- PRINT #2,
- PRINT #2,"Read: ";STR$(LMax);" lines from source file ";_
- UCASE$(InFileName$)
- PRINT #2,"Found: ";STR$(WpMax);" non-comment words."
- PRINT #2,"Times: Start: ";SP$,"End: ";EP$," Elapsed: ";
- PRINT #2,fnSecondsToTime$(fnElapsedSeconds&(SP$,EP$))
- PRINT #2,
- PRINT #2,"Compared: ";STR$(WpMax);" non-comment words from source file ";_
- UCASE$(InFileName$)
- PRINT #2,"Found: ";STR$(WcMax);_
- " non-reserved words (variables, labels, procedures)"
- PRINT #2,"Times: Start: ";SC$,"End: ";EC$," Elapsed: ";
- PRINT #2,fnSecondsToTime$(fnElapsedSeconds&(SC$,EC$))
- PRINT #2,
- PRINT #2,"Sorted: ";STR$(Wc);_
- " non-reserved words (variables, labels, procedures)"
- PRINT #2,"Times: Start: ";SS$,"End: ";ES$," Elapsed: ";
- PRINT #2,fnSecondsToTime$(fnElapsedSeconds&(SS$,ES$))
- PRINT #2,
- PRINT #2,"Printed: ";STR$(Wu);" unique, non-reserved words to ";_
- UCASE$(OutFileName$)
- PRINT #2,"Times: Start: ";SF$,"End: ";EF$," Elapsed: ";
- PRINT #2,fnSecondsToTime$(fnElapsedSeconds&(SF$,EF$))
- PRINT #2,
- PRINT #2,"Totals: Start: ";SP$,"End: ";EF$," Elapsed: ";
- PRINT #2,fnSecondsToTime$(fnElapsedSeconds&(SP$,EF$))
- PRINT #2,
- PRINT #2,"Word Array Size: ";
- PRINT #2,USING "######,";ArrayBytes&;
- PRINT #2," bytes"
- PRINT #2,"Default Word Array Dim.: ";
- PRINT #2, USING "#####,";WordArraySize;
- PRINT #2," wds";
- PRINT #2,TAB(38);"Actual Word Array Dim.: ";
- PRINT #2, USING "#####,";WpMax;
- PRINT #2," wds"
- PRINT #2,"Default Avg.Word Length: ";
- PRINT #2,USING "##";AvgWordLen;
- PRINT #2," byt";
- PRINT #2,TAB(38);"Actual Avg.Word Length: ";
- PRINT #2,USING "##";CINT(ArrayBytes& /WpMax);
- PRINT #2," byt"
- PRINT #2,"Default Packing Factor: ";
- PRINT #2, USING "###.##";PackingFactor!*100;
- PRINT #2," %";
- PRINT #2,TAB(38);"Actual Packing Factor: ";
- PRINT #2, USING "###.##";ArrayBytes&/InFileSize!*100;
- PRINT #2," %"
- PRINT #2,
- PRINT #2,"Source, ";UCASE$(InFileName$);",";TAB(26);"File size:";TAB(37);
- PRINT #2,USING "######,";InFileSize!;
- PRINT #2," bytes"
- PRINT #2,"Cross-Ref, ";UCASE$(OutFileName$);",";TAB(26);"File size:";TAB(37);
- OutFileSize! =LOF(2) 'Outfile size in bytes.
- PRINT #2,USING "######,";OutFileSize!+17;
- PRINT #2," bytes"
- PRINT #2,CHR$(12);
- PRINT #2,CHR$(26); 'End of file char (^Z).
- CLOSE #2
- RETURN
-
-
- '─── print top of screen report ────────────────────────────────────────
- PrintScreenTop: 'Top of screen report.
-
- CLS
- CALL BlankLine(1,BG,FG) 'Blank crt line 1.
- LOCATE 1,1
- TOSTitle$ ="CrossBas Cross-Reference List for "+UCASE$(InFileName$)
- ' so far.
- PRINT fnCenterJust$(TOSTitle$,72)
- COLOR FG,BG
- PRINT
- PRINT "Options: Upper-case: ";
- IF UcaseFlag THEN PRINT "Yes"; ELSE PRINT "No";
- PRINT TAB(30);"Screen: ";
- IF ScreenFlag THEN PRINT "Yes"; ELSE PRINT "No";
- PRINT TAB(49);"Paginate: ";
- IF PageFlag THEN PRINT "Yes" ELSE PRINT "No"
- PRINT " Left Margin:";STR$(LMargin);
- PRINT TAB(30);"ArrayDim:";
- IF WordDimFlag THEN
- PRINT STR$(WordArrayDim) 'Print over-ride value.
- ELSE
- PRINT " No o/r" 'No over-ride (/w:n).
- END IF
- RETURN
-
- '─── print screen report of words found ────────────────────────────────
- PrintScreen1: 'Read and parse words screen report.
-
- PRINT
- PRINT "Read: ";STR$(L);" lines from source file ";UCASE$(InFileName$)
- PRINT "Found: ";STR$(WpMax);" non-comment words."
- PRINT "Times: Start: ";SP$,"End: ";EP$," Elapsed: ";
- PRINT fnSecondsToTime$(fnElapsedSeconds&(SP$,EP$))
- DELAY 1
- RETURN
-
- '─── print screen report of words compared to reserved words ───────────
- PrintScreen2: 'Compare screen report.
-
- PRINT
- PRINT "Compared: ";STR$(WpMax);" non-comment words from source file ";_
- UCASE$(InFileName$)
- PRINT "Found: ";STR$(WcMax);_
- " non-reserved words (variables, labels, procedures)"
- PRINT "Times: Start: ";SC$,"End: ";EC$," Elapsed: ";
- PRINT fnSecondsToTime$(fnElapsedSeconds&(SC$,EC$))
- DELAY 1
- RETURN
-
- '─── print screen report of words sorted ───────────────────────────────
- PrintScreen3: 'Sort screen report.
-
- PRINT
- PRINT "Sorted: ";STR$(Ws);" non-reserved words (variables, labels, procedures)"
- PRINT "Times: Start: ";SS$,"End: ";ES$," Elapsed: ";
- PRINT fnSecondsToTime$(fnElapsedSeconds&(SS$,ES$))
- DELAY 1
- RETURN
-
- '─── print screen report of words printed ──────────────────────────────
- PrintScreen4: 'Print to file screen report.
-
- PRINT
- PRINT "Printed: ";STR$(Wu);" unique, non-reserved words to ";_
- UCASE$(OutFileName$)
- PRINT "Times: Start: ";SF$,"End: ";EF$," Elapsed: ";
- PRINT fnSecondsToTime$(fnElapsedSeconds&(SF$,EF$))
- PRINT
- PRINT "Totals: Start: ";SP$,"End: ";EF$," Elapsed: ";
- PRINT fnSecondsToTime$(fnElapsedSeconds&(SP$,EF$))
- PRINT
- PRINT "CrossBas finished.";
- CALL PushCursor
- CALL BlankLine(25,FG,BG)
- CALL PopCursor
- RETURN
-
- '─── initialize status bar for read and parse ──────────────────────────
- InitStatusBarP: 'Initialize status bar for read and parse.
-
- CALL PushCursor 'Save cursor position.
- CALL BlankLine(25,BG,FG) 'Blank crt line 25.
- LOCATE 25,2,0
- PRINT "Line: Word:"; 'Print status bar text.
- LOCATE 25,30
- PRINT "CrossBas collecting words in ";UCASE$(InFileName$);
- COLOR FG,BG
- CALL PopCursor 'Restore cursor position.
- RETURN
-
-
- '─── initialize status bar for compare ─────────────────────────────────
- InitStatusBarC: 'Initialize status bar for compare.
-
- CALL PushCursor 'Save cursor position.
- CALL BlankLine(25,BG,FG) 'Blank crt line 25.
- LOCATE 25,2,0
- PRINT "Word:"; 'Print status bar text.
- LOCATE 25,30
- PRINT "CrossBas comparing words in ";UCASE$(InFileName$);
- COLOR FG,BG
- CALL PopCursor 'Restore cursor position.
- RETURN
-
-
- '─── initialize status bar for sort ────────────────────────────────────
- InitStatusBarS: 'Initialize status bar for sort.
-
- CALL PushCursor 'Save curosr position.
- CALL BlankLine(25,BG,FG) 'Blank crt line 25.
- LOCATE 25,2,0
- PRINT "Pass:"; 'Print status bar text.
- LOCATE 25,30
- PRINT "CrossBas sorting words in ";UCASE$(InFileName$);
- COLOR FG,BG
- CALL PopCursor 'Restore cursor position.
- RETURN
-
- '─── initialize status bar for file print ──────────────────────────────
- InitStatusBarF: 'Initialize status bar for print to file.
-
- CALL PushCursor 'Save cursor position.
- CALL BlankLine(25,BG,FG) 'Blank crt line 25.
- LOCATE 25,2,0
- PRINT "Page: Word:"; 'Print status bar text.
- LOCATE 25,30
- PRINT "CrossBas writing words to ";UCASE$(OutFileName$);
- COLOR FG,BG
- CALL PopCursor 'Restore cursor position.
- RETURN
-
- '─── update status bar for read and parse ──────────────────────────────
- UpdateStatusBarP: 'Update status bar for read and parse.
-
- CALL PushCursor 'Save cursor position.
- LOCATE 25,8
- COLOR BG,FG
- PRINT USING "#####,"; L; 'Print current source line
- LOCATE 25,21 ' number.
- PRINT USING "######,";Wp; 'Print current source word
- COLOR FG,BG ' number.
- CALL PopCursor 'Restore cursor position.
- RETURN
-
- '─── update status bar for compare ─────────────────────────────────────
- UpdateStatusBarC: 'Compare
-
- CALL PushCursor 'Save cursor position.
- LOCATE 25,8
- COLOR BG,FG
- PRINT USING "#####,"; Wc; 'Print current compare word
- COLOR FG,BG ' number.
- CALL PopCursor 'Restore cursor position.
- RETURN
-
- '─── update status bar for sort ────────────────────────────────────────
- UpdateStatusBarS: 'Sort
-
- CALL PushCursor 'Save cursor position.
- LOCATE 25,8
- COLOR BG,FG
- PRINT USING "#####,"; J; 'Print current sort word
- COLOR FG,BG ' number.
- CALL PopCursor 'Restore cursor position.
- RETURN
-
- '─── update status bar for file print ──────────────────────────────────
- UpdateStatusBarF: 'Write to file.
-
- CALL PushCursor 'Save cursor position.
- LOCATE 25,8
- COLOR BG,FG
- PRINT USING "#####,"; Page; 'Print current page number.
- LOCATE 25,21
- PRINT USING "######,";Wu; 'Print current unique word
- COLOR FG,BG ' number.
- CALL PopCursor 'Restore cursor position.
- RETURN
-
- '─── ignore errors ─────────────────────────────────────────────────────
- NulError: 'Ignore errors.
-
- ErrorFlag =-1 'Set error flag.
- RESUME NEXT
-
-
- '─── in file rrror routine ─────────────────────────────────────────────
- InFileError: 'InFile error routine.
-
- IF INSTR(InFile$,".") =0 THEN 'If file error found and infile
- InFile$ =InFile$ +".bas" ' has no extension, append
- RESUME 0 ' '.bas' and try again.
- ELSE
- BadFile$ =InFile$
- GOTO BadFileName
- END IF
-
- '─── out file error routine ────────────────────────────────────────────
- OutFileError: 'OutFile error routine.
-
- IF NOT OutFileFlag THEN 'If haven't already tried
- ' new name then try one.
- IF INSTR(InFile$,".") =0 THEN 'If file/path is invalid
- OutFileFlag =-1 ' then append '.cb' to
- OutFile$ =InFile$ +".cb" ' infile name and try again.
- RESUME 0
- ELSE
- OutFileFlag =-1
- OutFile$ =LEFT$(InFile$,INSTR(InFile$,".")-1) +".cb"
- RESUME 0
- END IF
- ELSE
- BadFile$ =OutFile$
- GOTO BadFileName
- END IF
-
-
- '─── bad file name ─────────────────────────────────────────────────────
- BadFileName: 'Bad source file name. Tell the user and die.
-
- COLOR FG,BG
- CLS
- CLOSE
- PRINT "The file, ";UCASE$(BadFile$); " was not found. Please try again."
- CLOSE
- DELAY 1
- CALL FlushKeyBuf
- END
-
-
- '─── bad memory or other error ─────────────────────────────────────────
- MemoryError:
-
- IF (ERR =242 OR ERR =9) THEN 'Bad word array dimension.
- ProjArraySize =(InFileSize! /(LOC(1) *128)) *Wp
- ProjArraySize =FIX((ProjArraySize *1.05)) +1 'Add a little extra.
- COLOR FG,BG
- CLS
- PRINT "The word array dimension was too small."
- PRINT
- GOSUB ErrorScrnRpt
- PRINT
- IF (NOT WordDimFlag) OR_
- ((InFileSize! *PackingFactor! /AvgWordLen) <ProjArraySize) THEN
- PRINT "Try again using the /w:";
- PRINT RIGHT$(STR$(ProjArraySize),LEN(STR$(ProjArraySize))-1);
- PRINT " command line switch."
- ELSE
- PRINT "Try again without using the /w:n command line switch."
- END IF
- CLOSE
- DELAY 1
- CALL FlushKeyBuf
- END
- ELSEIF ERR =14 THEN 'Out of string space.
- COLOR FG,BG
- CLS
- PRINT "The string space is exausted. Source file, ";
- PRINT UCASE$(InFileName$);", is too large "
- PRINT "for CrossBas to handle."
- PRINT
- GOSUB ErrorScrnRpt
- PRINT
- PRINT "Try breaking the file up into one main file and one or ";
- PRINT "more INClude files."
- DELAY 1
- CLOSE
- CALL FlushKeyBuf
- END
- ELSE
- GOTO CatchRuntimeError
- END IF
-
-
- '─── catch runtime error ───────────────────────────────────────────────
- CatchRuntimeError: 'Catch unexpected errors.
-
- CLS
- CLOSE
- CALL CatchRuntime 'Print various memory values.
- DELAY 1
- CALL FlushKeyBuf 'Flush key buffer.
- END
-
- '─── no file spec found on command line ────────────────────────────────
- NoFileSpec: 'No filespec found on command line. Print basic
- ' instructions and syntax and die.
-
- CLS
- PRINT " CrossBas Source File Cross-Referencer for Power-BASIC"
- LOCATE 1,1: PRINT "ver. ";Ver$
- PRINT
- PRINT " CrossBas reads in a Power-BASIC source file (ASCII) and prints ";_
- "out a variable"
- PRINT " cross-reference list to a text file. Variable names are listed ";_
- "alphabetically,"
- PRINT " followed by the physical source file lines where they appear."
- PRINT
- PRINT " Switches: /bw Set screen colors to black & white."
- PRINT " /p Paginate output file and print page headers."
- PRINT " /u Print variables in output file in upper case."
- PRINT " /s Print the list to the screen as well as to file."
- PRINT " /l:n Set the printer left margin n columns."
- PRINT " /w:n Over-ride CrossBas' word array dimension calculation."
- PRINT
- PRINT " Syntax:"
- PRINT " crossbas infile[.ext] [outfile][.ext] ";_
- "[/bw][/p][/u][/s][/l:n][/w:n]"
- DELAY 1
- CALL FlushKeyBuf
- END
-
-
- '─── error report to screen ────────────────────────────────────────────
- ErrorScrnRpt:
-
- PRINT "Memory Statistics:"
- PRINT "Stack Space: ";
- PRINT USING "######,"; FRE(-2);
- PRINT TAB(28); "Array Space: ";
- PRINT USING "######,"; FRE(-1);
- PRINT TAB(52); "String Space: ";
- PRINT USING "######,"; FRE(S$)
- PRINT "End of Memory: ";
- PRINT USING "#######,"; ENDMEM;
- PRINT TAB(52); "String Segment: ";
- PRINT USING "\ \";fnHexFill$(FRE(S$),4)
- IF FRE(S$) <300 THEN ERASE Word$ 'If out of string segment, we
- ' must free some for this report.
- PRINT
- IF ERR >0 THEN
- PRINT "Error #"; STR$(ERR); " occurred at PC counter "; STR$(ERADR)
- PRINT fnErrorMsg$
- END IF
- IF ERDEV >0 THEN
- PRINT "Error Device: "; ERDEV$; ", Dev #"; STR$(ERDEV)
- END IF
- IF ERR >0 OR ERDEV >0 THEN PRINT
- PRINT "Source File Size: ";
- PRINT USING "#######,"; InFileSize!;
- PRINT " bytes"
- PRINT "Read so far: ";
- IF Wp >0 THEN
- PRINT USING "######,"; LOC(1) *128;
- ELSE
- PRINT USING "######,"; 0;
- END IF
- PRINT " bytes"; TAB(52);
- IF Wp >0 THEN
- PRINT USING "###.##"; LOC(1) *128 /InFileSize! *100;
- ELSE
- PRINT USING "###.##,"; 0;
- END IF
- PRINT " %"
- PRINT
- PRINT "Words Read:"; TAB(14);
- PRINT USING "#####,"; Wp;
- PRINT " words";TAB(35); "Projected Total: "; TAB(52);
- IF Wp >0 THEN
- PRINT USING "#####,"; InFileSize! /(LOC(1) *128) *Wp;
- ELSE
- PRINT USING "#####,"; 0;
- END IF
- PRINT " words"
- PRINT TAB(13);
- PRINT USING "######,"; ArrayBytes&;
- PRINT " bytes";TAB(51);
- IF Wp >0 THEN
- PRINT USING "######,"; InFileSize! /(LOC(1) *128) *ArrayBytes&;
- ELSE
- PRINT USING "######,"; 0;
- END IF
- PRINT " bytes"
- PRINT "Word Array Dimension:"
- PRINT TAB(5);"Active: ";
- PRINT USING "#####,"; WordArraySize;
- PRINT " words";TAB(35); "Over-ride:";TAB(52);
- IF WordDimFlag THEN
- PRINT USING "#####,"; WordArrayDim;
- PRINT " words"
- ELSE
- PRINT " No o/r"
- END IF
- PRINT "Average Word Length:"
- PRINT TAB(5);"Default: ";
- PRINT USING "#####,"; AvgWordLen;
- PRINT " bytes";TAB(35);"Calculated:";TAB(52);
- IF Wp >0 THEN
- PRINT USING "#####,"; ArrayBytes& /Wp;
- ELSE
- PRINT USING "#####,"; 0;
- END IF
- PRINT " bytes"
- PRINT "Packing Factor:"
- PRINT TAB(5);"Default: ";
- PRINT USING "#.##,"; PackingFactor!;
- PRINT TAB(35);"Calculated:";TAB(53);
- IF Wp >0 THEN
- PRINT USING "#.##,"; ArrayBytes& /(LOC(1) *128)
- ELSE
- PRINT USING "#.##,"; 0
- END IF
- RETURN
-
-
- '─── basic reserved word data ──────────────────────────────────────────
- WordData:
-
- DataDs:
- DATA $COM, $COM1, $COM2, $COMPILE, $CPU, $DEBUG, $DYNAMIC, $ELSE, $ENDIF
- DATA $ERROR, $EVENT, $FLOAT, $IF, $INCLUDE, $INLINE, $LIB, $LINK, $LIST
- DATA $OPTION, $SEGMENT, $SOUND, $STACK, $STATIC, $STRING, 0
-
- DataA:
- DATA ABS(), ABSOLUTE, AND, ANY, APPEND, ARRAY, AS, ASC(), ASCEND, ASCII()
- DATA AT, ATN(), 0
-
- DataB:
- DATA BASE, BEEP, BIN$(), BINARY, BLOAD, BSAVE, 0
-
- DataC:
- DATA CALL, CASE, CBCD(), CDBL(), CEIL(), CTEXT(), CFIX(), CHAIN, CHDIR
- DATA CHR$(), CINT(), CIRCLE(), CLEAR, CLNG(), CLOSE, CLS, COLLATE
- DATA COLOR, COM(), COMMAND$, COMMON, COS(), CQUD(), CSNG(), CSRLIN
- DATA CVB(), CVD(), CVE(), CVF(), CVI(), CVL(), CVMD(), CVMS(), CVQ()
- DATA CVS(), 0
-
- DataD:
- DATA DATA, DATE$, DECLARE, DECR, DEF, DEFBCD, DEFDBL, DEFEXT, DEFFIX
- DATA DEFFLX, DEFINT, DEFLNG, DEFQUD, DEFSNG, DEFSTR, DELAY, DELETE
- DATA DESCEND, DIM, DO, DRAW, DYNAMIC, 0
-
- DataE:
- DATA ELSE, ELSEIF, END, ENDMEM, ENVIRON, ENVIRON$(), EOF(), EQV, ERADR
- DATA ERASE, ERDEV, ERDEV$, ERL, ERR, ERROR, EXECUTE, EXIT, EXP()
- DATA EXP10(), EXP2(), EXTERNAL, EXTRACT$(), 0
-
- DataF:
- DATA FIELD, FILEATTR(), FILES, FIX(), FIXDIGITS, FLEXCHR$, FN, FOR, FRE()
- DATA FREEFILE, FROM, FUNCTION, 0
-
- DataG:
- DATA GET, GET(), GET$, GOSUB, GOTO, 0
-
- DataH:
- DATA HEX$(), 0
-
- DataI:
- DATA IF, IMP, IN, INCR, INKEY$, INP(), INPUT, INPUT #, INPUT$()
- DATA INSERT, INSTAT, INSTR(), INT(), INTERRUPT, IOCTL, IOCTL$, 0
-
- DataJ:
- DATA 0
-
- DataK:
- DATA KEY, KEY(), KILL, 0
-
- DataL:
- DATA LBOUND(), LCASE$(), LEFT$(), LEN(), LET, LINE, LINE(), LIST, LOC(), LOCAL
- DATA LOCATE, LOF(), LOG(), LOG10(), LOG2(), LOOP, LPOS(), LPRINT, LPRINT #
- DATA LSET, LTRIM$(), 0
-
- DataM:
- DATA MAP, MAX(), MAX$(), MAX%(), MEMSET, MID$(), MIN(), MIN$(), MIN%()
- DATA MKDIR, MKB$(), MKD$(), MKE$(), MKF$(), MKI$(), MKL$(), MKMD$()
- DATA MKMS$(), MKQ$(), MKS$(), MOD, MTIMER, 0
-
- DataN:
- DATA NAME, NEXT, NOT, 0
-
- DataO:
- DATA OCT$(), OFF, ON, OPEN, OPTION, OR, OUT, OUTPUT, 0
-
- DataP:
- DATA PAINT(), PALETTE, PEEK(), PEEK$(), PEEKI(), PEEKL(), PEN, PEN()
- DATA PLAY, PLAY(), PMAP(), POINT(), POKE, POKE$, POKEI, POKEL, POS
- DATA POS(), PRESET, PRINT, PRINT #, PSET(), PUBLIC, PUT, PUT(), PUT$, 0
-
- DataQ:
- DATA 0
-
- DataR:
- DATA RANDOM, RANDOMIZE, READ, REDIM, REG, REG(), REM, REMOVE$(), REPEAT$()
- DATA REPLACE, RESET, RESTORE, RESUME, RETURN, RIGHT$(), RMDIR, RND, RND()
- DATA ROUND(), RSET, RTRIM$(), RUN, 0
-
- DataS:
- DATA SAVE, SCAN, SCREEN, SCREEN(), SEEK, SEG, SELECT, SERVICE, SGN()
- DATA SHARED, SHELL, SIN(), SORT, SOUND, SPACE$(), SPC(), SQR(), STATIC
- DATA STEP, STICK(), STOP, STR$(), STRIG, STRIG(), STRING$(), STRPTR()
- DATA STRSEG(), SUB, SWAP, SYSTEM, 0
-
- DataT:
- DATA TAB(), TAGARRAY, TALLY(), TAN(), THEN, TIME$, TIMER, TIMER(), TO
- DATA TROFF, TRON, 0
-
- DataU:
- DATA UBOUND(), UCASE, UCASE$(), UNTIL, USING, USING$(), USR, USR0, USR1
- DATA USR2, USR3, USR4, USR5, USR6, USR7, USR8, USR9, 0
-
- DataV:
- DATA VAL(), VARPTR(), VARPTR$(), VARSEG(), VERIFY(), VIEW, VIEW(), 0
-
- DataW:
- DATA WAIT, WEND, WHILE, WIDTH, WINDOW, WINDOW(), WITH, WRITE, WRITE #, 0
-
- DataX:
- DATA XOR, 0
-
- DataY:
- DATA 0
-
- DataZ:
- DATA 0
-
- '┌── end of crossbas.bas ──────────────────────────────────────────────┐
- '└─────────────────────────────────────────────────────────────────────┘
-